package gunfire.actions;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import gunfire.GunfireMod;
import gunfire.cards.FieldSupport;

import java.util.ArrayList;

public class FieldSupportAction extends AbstractGameAction {

    public FieldSupportAction(){}

    @Override
    public void update() {
        AbstractPlayer p = AbstractDungeon.player;
        ArrayList<AbstractCard> temps = new ArrayList<>();
        int handSize = p.hand.size();
        boolean isFull = false;
        for(AbstractCard c : p.drawPile.group){
            if(c instanceof FieldSupport){
                if(handSize == 10){
                    isFull = true;
                    break;
                }
                handSize++;
                temps.add(c);
            }
        }

        for(AbstractCard c : temps){
            c.unhover();
            c.lighten(true);
            c.setAngle(0.0F);
            c.drawScale = 0.12F;
            c.targetDrawScale = 0.75F;
            c.current_x = CardGroup.DRAW_PILE_X;
            c.current_y = CardGroup.DRAW_PILE_Y;
            p.drawPile.removeCard(c);
            AbstractDungeon.player.hand.addToHand(c);
            AbstractDungeon.player.hand.refreshHandLayout();
            AbstractDungeon.player.hand.applyPowers();
        }

        if(isFull){
            p.createHandIsFullDialog();
        }

        this.isDone = true;
    }
}
